package com.rabbitmq.demo.datasource;

import com.rabbitmq.demo.entity.Order;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @AUTHOR: yb.feng
 * @DATE: 2021/1/26 16:34
 * @DESC:
 */
public class OrderSource {

    private static Map<String, List<Order>> datasource;

    static {
        datasource = new HashMap<>(10);
    }

    public static  List<Order> getOrders(String userName){
        return datasource.get(userName);
    }

    public static void save(Order order){
        List<Order> orders = getOrders(order.getUserName());
        if (orders == null){
            orders = new ArrayList<>();
            orders.add(order);
            datasource.put(order.getUserName(), orders);
        }
        orders.add(order);
    }
}
